package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.bean.CancelMultipleReservationBean;
import com.ricchieri.common.BusinessSettings;
import com.ricchieri.model.User;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewCancelMultipleReservationMB")
@ViewScoped
public class ViewCancelMultipleReservationManageBean extends CommonCancelMultipleReservationManageBean {

	private static final long serialVersionUID = -4431457088573798836L;
	
	private User selectedUser;
	private CancelMultipleReservationBean cancelMultipleReservationBean;
	
	@PostConstruct
	public void init() {
		selectedUser = (User) FacesUtil.getParametersFlash(BusinessSettings.KEY_USER);
		cancelMultipleReservationBean = (CancelMultipleReservationBean) FacesUtil.getParametersFlash(BusinessSettings.KEY_MULTIPLE_CANCELATION);
		
		if(cancelMultipleReservationBean == null && selectedUser == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.HOME_RESERVATION);
		}
	}

	public User getSelectedUser() {
		return selectedUser;
	}

	public void setSelectedUser(User selectedUser) {
		this.selectedUser = selectedUser;
	}

	public CancelMultipleReservationBean getCancelMultipleReservationBean() {
		return cancelMultipleReservationBean;
	}

	public void setCancelMultipleReservationBean(
			CancelMultipleReservationBean cancelMultipleReservationBean) {
		this.cancelMultipleReservationBean = cancelMultipleReservationBean;
	}
	
	public String cancelSameSchedule() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_MULTIPLE_CANCELATION, cancelMultipleReservationBean);
		FacesUtil.addParametersFlash(BusinessSettings.KEY_CANCEL_RESERVATION, BusinessSettings.KEY_CANCEL_RESERVATION_SCHEDULE);
		return BusinessSettings.CANCEL_MULTIPLE_RESERVATION;
	}
	
	public String cancelSameUser() {
		FacesUtil.addParametersFlash(BusinessSettings.KEY_USER, selectedUser);
		FacesUtil.addParametersFlash(BusinessSettings.KEY_CANCEL_RESERVATION, BusinessSettings.KEY_CANCEL_RESERVATION_USER);
		return BusinessSettings.CANCEL_MULTIPLE_RESERVATION;
	}

}
